package com.wyd.jwpkglxt_ssm.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class UploadUtil {

    //private static final String BASE_PATH = "D:\\apache-tomcat-9.0.38\\webapps\\upload\\";

    private static final String SERVER_PATH= "http://localhost:8989/ssm/upload/";

    public static String upload(MultipartFile file,String BASE_PATH){
        String filename = file.getOriginalFilename();
        String uuid = UUID.randomUUID().toString().replace("-","");
        String newFilename = uuid + "-" + filename;
        File image = new File(BASE_PATH,newFilename);
        try{
            file.transferTo(image);
        }catch (IOException e){
            e.printStackTrace();
        }
        return SERVER_PATH + newFilename;
    }
}
